Todo.Collection.Base = Backbone.Collection.extend({
    localStorage: new Backbone.LocalStorage(),

    initialize: function (options) {
        _.extend(this, options);
    },

    isNameExists: function (name) {
        name = $.trim(name);

        var items = this.filter(function (item) {
            return $.trim(item.get("name")).toLowerCase() === name.toLowerCase();
        });

        return (items.length > 0) ? items[0] : false;
    },

    nextOrder: function () {
        if (!this.length) return 1;
        return this.last().get('position') + 1;
    },

    comparator: function (item) {
        return item.get('position');
    },

    generateNewId: function () {
        var prefix = 'new_', id;

        while (true) {
            id = _.uniqueId(prefix);

            if (!this.get(id)) {
                break;
            }
        }

        return id;
    }
});